package icu.xuyijie.springbootlearning1.chapter4.file;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author 徐一杰
 * @date 2025/03/03 13:41
 * @description 文件相关操作
 */
@RestController
@RequestMapping("/file")
@Tag(name = "文件相关操作")
public class FileController {

    @PostMapping("/upload")
    @Operation(summary = "上传文件", description = "上传单个文件", parameters = {
            @Parameter(name = "multipartFile", description = "要上传的文件")
    })
    public void uploadFile(MultipartFile multipartFile) throws IOException {
        // 构建文件名
        String fileName = "D:\\下载\\" + multipartFile.getOriginalFilename();
        // 保存到构建的文件名中
        multipartFile.transferTo(new File(fileName));
    }

}
